import Vue    from 'vue';
import Router from 'vue-router';

Vue.use(Router);

import Home from "./home";
import Member from "./member";
import Login from "./login";
import Ordering from "./ordering";
import Shopping from "./shopping";
import Store from "./store";
import H5 from "./h5";
import Mall from "./mall";
import Rating from "./rating";
import Jim from "./jim";
import { iosapp } from "@/utils";


const $router =  new Router({
	routes: [].concat(
		Home,
		Login,
		Member,
		Shopping,
		Ordering,
		Store,
		H5,
		Mall,
		Rating,
		Jim
	)
})

// Before request
$router.beforeEach((to, from, next) => {
    //To do something
   

    if(!window.sessionStorage.getItem('uid') && to.path != '/login'){

      	window.sessionStorage.setItem('beforeLoginUrl', to.fullPath); // 保存用户进入的url
    }
    next();

    let url = window.location.href;
	let isApp = url.indexOf('isiOS=1');

	if(isApp != -1)
		window.sessionStorage.setItem('isapp','1');
	
    
});
// After request
$router.afterEach(route => {
    document.title = route.meta.title;

	switch(route.path)
	{
		case '/':
    	case '/ordering':
    	case '/shopping':
    	case '/member':
    		break;
		default:
			var parameter = {
				'title' : route.meta.title
			}

    		iosapp('ExperienceGoHeadAction',parameter)
    			break;
	}
});

export default $router;